package po;

import java.util.ArrayList;

public class CashRecordList {
	ArrayList<CashRecordLineItem>  list;
	double total;
	double getTotal(){
		return total;
	}
	
	public boolean add(CashRecordLineItem item){
		total += item.getSum();
		return list.add(item);
	}

	public boolean delete(String name,double sum,String comment){
		CashRecordLineItem item = find(name,sum,comment);
		return list.remove(item);
	}
	
	public boolean update(String name,double sum,String comment,String newName,double newSum,String newComment){
		CashRecordLineItem item = find(name,sum,comment);
		if(item != null){
			item.set(newName, newSum, newComment);
			return true;
		}
		return false;
	}
	
	public CashRecordLineItem find(String name,double sum,String comment){
		for(CashRecordLineItem item : list){
			if(item.match(name, sum, comment)){
				return item;
			}
		}
		return null;
	}
	
}
